<HTML>
	<HEAD>
		<link rel="stylesheet" type="text/css" href="<?=$base?>bud/css/jquery.treeview.css" />
		<link rel="stylesheet" type="text/css" href="<?=$base?>bud/css/screen.css" />
		<script type="text/javascript" src="<?=$base?>bud/css/jquery.js" ></script>
		<script type="text/javascript" src="<?=$base?>bud/css/jquery.cookie.js"></script>
		<script type="text/javascript" src="<?=$base?>bud/css/jquery.treeview.js"></script>	
		<script type="text/javascript" src="<?=$base?>bud/css/demo.js"></script>
		<script type="text/javascript" src="<?=$base?>bud/css/numericvalidation.js"></script>
		</script>
	</HEAD>
<BODY>
	<H2>Budget : <?=$versi;?></H2>
	
<?php
	function convert($val){
		if($val>=1){
			return ("<IMG SRC=\"".base_url()."images/icons/fugue/tick.png\">");
		}else{
			return ("<IMG SRC=\"".base_url()."images/icons/fugue/minus.png\">");
		}
	}

	function addSeparator($val){
		return number_format($val,2,',','.');
	}
 
	if($view_option=='manager' || $view_option=='admin'){
		echo "<div id='flash_message'>";
		echo "<B>Versi sebelumnya</B><HR>";
		foreach ($change as $key=>$val){
			echo $key." : ".$val."<BR>";
		}
		echo "</div>";
		echo '<hr>';
		echo form_open('bud/bud_revisi/process_revisi/detail', array('name'=>'form_main'));
	?>
		<ul id="red" class="treeview-red">
			<h3>Program</h3>
			<?php foreach($content as $keyprog=>$valprog):?>
				<li><span><B><?=$keyprog?></B></span><span id="<?=substr($keyprog,0,strpos($keyprog,' '));?>"></span>
					<?php if(is_array($content[$keyprog])):?>
						<ul>
						<h3>Activity</h3>
						<?php foreach($content[$keyprog] as $keyact=>$valact):?>
							<li><span><?=$keyact?></span><span id="<?=substr($keyact,0,strpos($keyact,' '));?>"></span>
								<ul>
									<I><?=$valact->desc_activity?></I>
									<hr>
									<?php
										$table_detail = new MY_Table(); 
										$table_mark = new MY_Table();
										
										//Set Template

										$templ_detail = array(
											'table_open' => '<table border= "1" height="300" width="500" class="table">',
											'table_close' => '</table>'
										);
										$templ_mark = array(
											'table_open' => '<table border= "1" height="300" width="300" class="table">',
											'table_close' => '</table>'
										);


										//Detail
										$detail_element = array (		
											  '<B>Total</B>'=> "<SPAN id='total:".$valact->key."'>Rp. ".addSeparator($valact->gaji_honor+$valact->barang_tak_habis+$valact->barang_habis+$valact->jasa_honor_ext+$valact->perjalanan)."</SPAN><SPAN id='jumlah:".$valact->key."' style='float:right;'></SPAN>",
											  '--Gaji'=>			form_input(array('name'=>$valact->key.'[gaji_honor]','value'=>$valact->gaji_honor,'onkeyup'=>'strip_nonnumeric(this); checkChange(this); recalculate_total(\''.$valact->key.'\');', 'style'=>'text-align:right', 'title'=>$valact->gaji_honor)),
											  '--Barang Habis'=>	form_input(array('name'=>$valact->key.'[barang_habis]','value'=>$valact->barang_habis,'onkeyup'=>'strip_nonnumeric(this); checkChange(this); recalculate_total(\''.$valact->key.'\');', 'style'=>'text-align:right', 'title'=>$valact->barang_habis)),
											  '--Barang Tak Habis'=>form_input(array('name'=>$valact->key.'[barang_tak_habis]','value'=>$valact->barang_tak_habis,'onkeyup'=>'strip_nonnumeric(this); checkChange(this); recalculate_total(\''.$valact->key.'\');', 'style'=>'text-align:right', 'title'=>$valact->barang_tak_habis)),
											  '--Perjalanan'=>      form_input(array('name'=>$valact->key.'[perjalanan]','value'=>$valact->perjalanan,'onkeyup'=>'strip_nonnumeric(this); checkChange(this); recalculate_total(\''.$valact->key.'\');', 'style'=>'text-align:right', 'title'=>$valact->perjalanan)),
											  '--Jasa Lain'=>		form_input(array('name'=>$valact->key.'[jasa_honor_ext]','value'=>$valact->jasa_honor_ext,'onkeyup'=>'strip_nonnumeric(this); checkChange(this); recalculate_total(\''.$valact->key.'\');', 'style'=>'text-align:right', 'title'=>$valact->jasa_honor_ext)),
											  'Volume'=>$valact->volume,
											  'Sumber'=>$valact->key_bud_r_sumber,
											  'Unit'=>$valact->key_bud_r_unit,
											  'Aktivitas yayasan'=>$valact->key_bud_m_yayasan_activity,
											  'Program'=>$valact->key_bud_m_program,
										);


										$mark_element = array (

											'Januari'=>convert($valact->januari),
											'Februari'=>convert($valact->februari),
											'Maret'=>convert($valact->maret),
											'April'=>convert($valact->april),
											'Mei'=>convert($valact->mei),
											'Juni'=>convert($valact->juni),
											'Juli'=>convert($valact->juli),
											'Agustus'=>convert($valact->agustus),
											'September'=>convert($valact->september),
											'Oktober'=>convert($valact->oktober),
											'November'=>convert($valact->november),
											'Desember'=>convert($valact->desember)			
										);

										$table_detail->set_template($templ_detail);

										foreach($detail_element as $key=>$val){
											$table_detail->add_row('<FONT size="2">'.$key.'</FONT>','<FONT size="2">'.$val.'</FONT>');
										}

										//Mark
										$table_mark->set_template($templ_mark);				
										
										foreach($mark_element as $key=>$val){
											$table_mark->add_row('<FONT size="2">'.$key.'</FONT>','<FONT size="2">'.$val.'</FONT>');
										}
															
									?>
									
									<TABLE border= "4" height="200" width="800" class="table">
										<TR>
											<TD colspan='2' align="CENTER">
												<FONT size="3"><B>Detail Budget</B></FONT>
											</TD>
										</TR>
										<TR>
											<TD>
												<?=$table_detail->generate();?>
											</TD>
											<TD>
												<?=$table_mark->generate();?>
											</TD>
										</TR>
									</TABLE>	

									<?php
										//$table_detail->clear();	
										//$table_mark->clear();
									?>
								</ul>
							</li>
						<?php endforeach;?>
						</ul>
					<?php endif;?>
				</li>
			<?php endforeach;?>
		</ul>
	<?
		echo '<input type="submit" value="Save"/>'.'|'.anchor('bud/bud_revisi',form_button('cancel','cancel'));
		echo form_close();
	}else{
		redirect(base_url());								
	}
?>
<script language="JavaScript">
  var text = "";
  function checkValue(field_name,def){
	field = document.form_main.elements[field_name];
	if(field.value!=def){
		field.style.background = "#FFEE99";
	}else{
		field.style.background = "#FFFFFF";
	}
  }

 function checkChange(that){
	var elements = document.getElementsByTagName('SPAN');
	var i;
	var text;
	
	if(that.value != that.title){
		for (i=0; i<elements.length; i++) {
			if(elements[i].id.length != 0 ){
				if(that.name.indexOf(elements[i].id)==0){
					elements[i].innerHTML= "<IMG SRC=\"http://syp.si.del.ac.id/images/icons/fugue/highlighter.png\">";
				}
			}
		}
	}else{
		for (i=0; i<elements.length; i++) {
			if(elements[i].id.length != 0 ){
				if(that.name.indexOf(elements[i].id)==0){
					elements[i].innerHTML= "";
				}
			}
		}
	}
  }

  function recalculate_total(name) {
		var elements = document.forms[0].elements;
		var i;
		var name;
		var value;

		var total = 0.00;
		document.getElementById("jumlah:"+name).innerHTML = total;
		for (i=0; i<elements.length; i++) {
			if (elements[i].name.indexOf(name)==0) {
				value = parseFloat(elements[i].value);
				if (isNaN(value)) {
					value = 0.00;
				}
				
				total = total + value;
			}
		}
		document.getElementById("jumlah:"+name).innerHTML = "="+(total);
   }

   /*function checkAll(){
	    var elements = document.forms[0].elements;
		var i,j;
		for(i=0; i<elements.length; i++){
			/*recalculate_total(elements[i].name);
			if(){
				alert(elements[i].name+"--"+elements[i].title);
			checkChange(elements[i]);
		}
   }*/

   

</script>
</BODY>
</HTML>
